/**
 * @author     Gabor Greif <ggreif@gmail.com>
 * @copyright  2009-2010 Gabor Greif
 * @license    http://www.opensource.org/licenses/mit-license.php  MIT License
 * @version    Release: 0.0
 */

#ifndef micker_COMMANDMAP_hpp
#define micker_COMMANDMAP_hpp

#include "Command.hpp"

#include <map>

namespace micker {

    class CommandMap : public std::map<std::string, Command>
    {
    public:
        std::string run(const std::string& command, const std::deque<std::string>& args)
            {
                iterator found(find(command));
                if (found != end())
                {
                    return found->second.first(*found->second.second, command, args);
                }
                return "[error {command not found}]";
            }

        std::string parseAndRun(const std::string& commandAndArgsRepeated);

        /// @brief a simpler insert method, does not leak
        void insert(const std::string& name, const Command& cmd);

        /// @brief destructor -- clean out all environment pointers
        ~CommandMap(void);

        /// @brief make available all insert methods from map
        /// @detail these are not leak-protected, thus private
    private:
        using std::map<std::string, Command>::insert;
    };

} // namespace

#endif // micker_COMMANDMAP_hpp
